package models

import (
	"192.168.1.75/go-pkg/helper"
	"gorm.io/gorm"
)

// Activity 活动表
type SupportActivity struct {
	ID             string `json:"id" gorm:"column:id;primaryKey;type:varchar(32);not null;comment:主键"`
	Name           string `json:"name" gorm:"column:name;type:varchar(100);not null;default:'';comment:活动名称"`
	StartTime      int64  `json:"start_time" gorm:"column:start_time;type:int;size:64;not null;default:0;comment:开始时间"`
	EndTime        int64  `json:"end_time" gorm:"column:end_time;type:int;size:64;not null;default:0;comment:结束时间"`
	MaterialIDs    string `json:"material_ids" gorm:"column:material_ids;type:text;not null;comment:素材ID列表,逗号分隔"`
	Status         int8   `json:"status" gorm:"column:status;type:tinyint(1);not null;default:1;comment:状态:1启用,2禁用"`
	CreateUser     string `json:"create_user" gorm:"column:create_user;type:varchar(30);not null;default:'';comment:创建用户ID"`
	CreateUserName string `json:"create_username" gorm:"column:create_username;type:varchar(50);not null;default:'';comment:创建用户名"`
	CreatedAt      int64  `json:"created_at" gorm:"column:created_at;autoCreateTime;type:int;size:64;not null;default:0;index:created_at;comment:创建时间"`
	UpdatedAt      int64  `json:"updated_at" gorm:"column:updated_at;autoUpdateTime;type:int;size:64;not null;default:0;comment:更新时间"`
	DeletedAt      int64  `json:"deleted_at" gorm:"column:deleted_at;type:int;size:64;not null;default:0;comment:删除时间"`
}

// TableName 表名
func (SupportActivity) TableName() string {
	return "support_activity"
}

// BeforeCreate 自动生成ID
func (a *SupportActivity) BeforeCreate(tx *gorm.DB) (err error) {
	if a.ID == "" {
		uuid, err := helper.UUID{}.String()
		if err != nil {
			return err
		}
		a.ID = uuid
	}
	return nil
}

// 模式自动注册
func init() {
	Models = append(Models, &SupportActivity{})
}
